#!/usr/bin/env python

# Custom modules
from authentication import user_required
from authentication import get_account_from_user
from models import Account
from models import Good
from models import Offer
from models import Log

# Built-in or Google modules
import cgi
import os
from google.appengine.ext.webapp import template
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.api import users
from google.appengine.ext.webapp.util import login_required
from google.appengine.ext import db

class LogView(webapp.RequestHandler):
    def get(self):
        user = users.get_current_user()
        curUser = get_account_from_user(user)
        logs = Log.all()
        
        template_values = {'accounts': Account.all(),
                           'cur_user': curUser,
                           'logs': logs}
        
        path = os.path.join(os.path.dirname(__file__), 'log.html')
        self.response.out.write(template.render(path, template_values))        

        
    def post(self):
        curUser = Account.get(self.request.get('account_key'))
        #logs = Log.recent_logs_for(curUser, 64)
        all_accounts = Account.all()
        logs = Log.all()
        """f = open('C:/logfile.txt', 'w')
        logs = Log.all()
        for log in logs:
            f.write(log.accountName)
        f.close()"""
        template_values = {'accounts': all_accounts,
                           'cur_user': curUser,
                           'logs': logs}
        
        path = os.path.join(os.path.dirname(__file__), 'log.html')
        self.response.out.write(template.render(path, template_values))
        
        
        
        


application = webapp.WSGIApplication(
                                     [('/log/view', LogView),],
                                     debug=True)									 
def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()

